set matsize 11000

* ) Insert directory
cd ""
use "Author-paper-referee level data", clear

***************************************
global refchars referee_Female referee_USNEWS_1 referee_USNEWS_2 referee_USNEWS_3 referee_yearsPhD ///
	referee_published_papers referee_published_from_5_no_pp referee_is_nber referee_employmentrank1 referee_employmentrank2 referee_employmentrank3 ///
	referee_employmentrank4 referee_degree_1
	
global authorcontrols female gender_missing published_papers published_from_5_no_pp USNEWS_1-USNEWS_5 is_nber ///
	employmentrank1 employmentrank2 employmentrank3 employmentrank4 employmentrank5 NBER_AG-NBER_PE degree_1 degree_2

gen ym = year*100+month

sum $authorcontrols

* ) Only do analysis for accepted papers
keep if status=="Accepted"

* ) Top-coding distance and include missing
replace referee_distance = 6 if referee_distance>6 | referee_distance==.
replace editor_distance = 6 if editor_distance>6 | editor_distance==.

*) When doing editor analysis, don't double count observations due to referee assignment
bysort ms_number_id editor_id author_id: gen indicate = 1 if _n==1

* ) For model with "number of direct connections between author and reviewer/editor"
gen referee_one_degree = (referee_distance==1)
gen editor_one_degree = (editor_distance==1)
gen referee_Nconnections = referee_one_degree + referee_phdmatch + referee_employmentmatch + referee_isnbermatch_program 
gen editor_Nconnections = editor_one_degree + editor_phdmatch + editor_employmentmatch + editor_isnbermatch_program 
drop referee_one_degree editor_one_degree
*Generating indicators for each category
tab referee_Nconnections, generate(referee_Nconnections_raw) m
tab editor_Nconnections, generate(editor_Nconnections_raw) m
*Top code 2+ connections
replace referee_Nconnections_raw3 = referee_Nconnections_raw3+referee_Nconnections_raw4
replace editor_Nconnections_raw3 = editor_Nconnections_raw3+editor_Nconnections_raw4+editor_Nconnections_raw5

*****************************************
*****************************************
*****************************************
*PhD Match
eststo clear

*PhD Institution 
eststo: reghdfe citations editor_phdmatch $authorcontrols [aweight=editor_weight] if indicate==1, absorb(editor_id ym) vce(cluster ms_number_id)
estadd local refFE "X",replace
estadd local paperFE " ",replace
estadd local authorcontrols "X",replace
*Same Employment
eststo: reghdfe citations editor_employmentmatch $authorcontrols [aweight=editor_weight] if indicate==1, absorb(editor_id ym) vce(cluster ms_number_id)
estadd local refFE "X",replace
estadd local paperFE " ",replace
estadd local authorcontrols "X",replace
*NBER programs
eststo: reghdfe citations editor_isnbermatch_program $authorcontrols [aweight=editor_weight] if indicate==1, absorb(editor_id ym) vce(cluster ms_number_id)
estadd local refFE "X",replace
estadd local paperFE " ",replace
estadd local authorcontrols "X",replace
*Degrees of separation
eststo: reghdfe citations editor_distance_raw1-editor_distance_raw3 $authorcontrols [aweight=editor_weight] if indicate==1, absorb(editor_id ym) vce(cluster ms_number_id)
estadd local refFE "X",replace
estadd local paperFE " ",replace
estadd local authorcontrols "X",replace
*Everything together
eststo: reghdfe citations editor_phdmatch editor_employmentmatch editor_isnbermatch_program editor_distance_raw1-editor_distance_raw3 $authorcontrols [aweight=editor_weight] if indicate==1, absorb(editor_id ym) vce(cluster ms_number_id)
estadd local refFE "X",replace
estadd local paperFE " ",replace
estadd local authorcontrols "X",replace
*Number of connections
eststo: reghdfe citations editor_Nconnections_raw2-editor_Nconnections_raw3 $authorcontrols [aweight=editor_weight] if indicate==1, absorb(editor_id ym) vce(cluster ms_number_id)
estadd local refFE "X",replace
estadd local paperFE " ",replace
estadd local authorcontrols "X",replace

label var editor_phdmatch "\underline{Outcome: Citations} \\ \ \ Exact same PhD institution "
label var editor_employmentmatch "\ \ Former/current colleagues"
label var editor_isnbermatch_program "\ \ Same NBER program(s)"
label var editor_distance_raw1 "\ \ Degrees of separation: 1"
label var editor_distance_raw2 "\ \ Degrees of separation: 2"
label var editor_distance_raw3 "\ \ Degrees of separation: 3"
label var editor_distance_raw4 "\ \ Degrees of separation: 4"
label var editor_distance_raw5 "\ \ Degrees of separation: 5"
label var editor_distance_raw6 "\ \ Degrees of separation: 6+"
label var editor_Nconnections_raw2 "\hline \# of direct matches: \\ \ \ - One match"
label var editor_Nconnections_raw3 "\ \ - Two+ matches"

label var female "\underline{Control variables}: \\ Female"
label var gender_missing "Gender missing"
label var USNEWS_1 "Institution of PhD (US News): \\ \ \ -Ranked top 10"
label var USNEWS_2 "\ \ -Ranked 11-30"
label var USNEWS_3 "\ \ -Ranked 31-50"
label var USNEWS_5 "\ \ -Ranked 51+ / missing"
label var published_papers "\# prior publications"
label var published_from_5_no_pp "\# prior top fives"
label var is_nber "NBER affiliated"
label var employmentrank1  "Department rank (IDEAS): \\ \ \ -Ranked top 10"
label var employmentrank2 "\ \ -Ranked 11-30"
label var employmentrank3 "\ \ -Ranked 31-100"
label var employmentrank4 "\ \ -Ranked 101-250"
label var employmentrank5 "\ \ -251+ / missing / non-academic"
label var degree_1 "\# of unique coauthors"
label var degree_2 "\# of coauthors' coauthors"

esttab using "editor_clubmatch_citations.tex", ///
    replace se(3) b(3) star(* 0.10 ** 0.05 *** 0.01) noobs nonum nonotes nogaps ///
	s(N refFE authorcontrols r2, label("Author-editor-papers" "Editor FE" "Author controls" "R-squared") fmt(%12.0f %12.3f)) ///
	mtitles("(1)" "(2)" "(3)" "(4)" "(5)" "(6)" "(7)" "(8)" "(9)" "(10)" "(11)" "(12)" "(13)" "(14)" "(15)") label ///
	keep(editor_phdmatch editor_employmentmatch editor_isnbermatch_program editor_distance* editor_Nconnections_raw2 editor_Nconnections_raw3)
	
*****************************************
*PhD Match
eststo clear

*PhD Institution
eststo: reghdfe citations referee_phdmatch $authorcontrols $refchars [aweight=hello], absorb(editor_id ym) vce(cluster ms_number_id)
estadd local editorFE "X"
estadd local refFE "X",replace
estadd local paperFE "X",replace
estadd local authorcontrols "X",replace
*Same Employment
eststo: reghdfe citations referee_employmentmatch $authorcontrols $refchars [aweight=hello], absorb(editor_id ym) vce(cluster ms_number_id)
estadd local editorFE "X"
estadd local refFE "X",replace
estadd local paperFE "X",replace
estadd local authorcontrols "X",replace
*NBER programs
eststo: reghdfe citations referee_isnbermatch_program $authorcontrols $refchars [aweight=hello], absorb(editor_id ym) vce(cluster ms_number_id)
estadd local editorFE "X"
estadd local refFE "X",replace
estadd local paperFE "X",replace
estadd local authorcontrols "X",replace
*Degrees of separation
eststo: reghdfe citations referee_distance_raw1-referee_distance_raw3 $authorcontrols $refchars [aweight=hello], absorb(editor_id ym) vce(cluster ms_number_id)
estadd local editorFE "X"
estadd local refFE "X",replace
estadd local paperFE "X",replace
estadd local authorcontrols "X",replace
*Everything together
eststo: reghdfe citations referee_phdmatch referee_employmentmatch referee_isnbermatch_program referee_distance_raw1-referee_distance_raw3 $authorcontrols $refchars [aweight=hello], absorb(editor_id ym) vce(cluster ms_number_id)
estadd local editorFE "X"
estadd local refFE "X",replace
estadd local paperFE "X",replace
estadd local authorcontrols "X",replace
*Number of connections
eststo: reghdfe citations referee_Nconnections_raw2-referee_Nconnections_raw3 $authorcontrols $refchars [aweight=hello], absorb(editor_id ym) vce(cluster ms_number_id)
estadd local editorFE "X"
estadd local refFE "X",replace
estadd local paperFE "X",replace
estadd local authorcontrols "X",replace

label var referee_phdmatch "\underline{Outcome: Citations} \\ \ \ Exact same PhD institution "
label var referee_employmentmatch "\ \ Former/current colleagues"
label var referee_isnbermatch_program "\ \ Same NBER program(s)"
label var referee_distance_raw1 "\ \ Degrees of separation: 1"
label var referee_distance_raw2 "\ \ Degrees of separation: 2"
label var referee_distance_raw3 "\ \ Degrees of separation: 3"
label var referee_distance_raw4 "\ \ Degrees of separation: 4"
label var referee_distance_raw5 "\ \ Degrees of separation: 5"
label var referee_distance_raw6 "\ \ Degrees of separation: 6+"
label var referee_Nconnections_raw2 "\hline \# of direct matches: \\ \ \ - One match"
label var referee_Nconnections_raw3 "\ \ - Two+ matches"

esttab using "referee_clubmatch_citations.tex", ///
    replace se(3) b(3) star(* 0.10 ** 0.05 *** 0.01) noobs nonum nonotes nogaps ///
	s(N editorFE refFE paperFE r2, label("Author-reviewer-papers" "Editor FE" "Reviewer controls" "Author controls" "R-squared") fmt(%12.0f %12.3f)) ///
	mtitles("(1)" "(2)" "(3)" "(4)" "(5)" "(6)" "(7)" "(8)" "(9)" "(10)" "(11)" "(12)" "(13)" "(14)" "(15)") label ///
	keep(referee_phdmatch referee_employmentmatch referee_isnbermatch_program referee_distance* referee_Nconnections_raw2 referee_Nconnections_raw3)
